#include "enib.h"

#include <GL/glut.h>
#include <iostream>

using namespace std;
/*
Enib::Enib() : Objet3D(), KeyboardListener()
{
  enib = new Plan(20,20, "tex_enib.png");
  sol = new Plan(20,20,"tex_sol.png");
  arriere = new Plan(40,40,"tex_arriere.png");
 (enib->getTexture())->setModePlaquage(GL_REPLACE);
 (sol->getTexture())->setModePlaquage(GL_REPLACE);
 (arriere->getTexture())->setModePlaquage(GL_REPLACE);
  _solSelec=false;
  _enibSelec=false;
  _arrSelec=false;
  _solY=0.0;
}

Enib::~Enib()
{
  delete enib;
  delete arriere;
  delete sol;
  delete ciel;
}

void Enib::onKeyboardEvent(unsigned char key, int x, int y)
{
  switch(key)
  {
    case 's' :
      _solSelec=true;
      _enibSelec=false;
      _arrSelec=false;
      break;
    case 'e' : 
      _enibSelec=true;
      _solSelec=false;
      _arrSelec=false;
      break;
    case 'a' : 
      _arrSelec=true;
      _solSelec=false;
      _enibSelec=false;
      break;
    case '8' : 
      if(_solSelec) _solY+=0.5;
      break;
    case '2' : 
      if(_solSelec) _solY-=0.5;
      break;
    default : 
      cout << hex << (long)(key) << endl;
      break;
  };
  cout << "sol Y : " << _solY << endl;
  glutPostRedisplay();
}

void Enib::_draw()
{
glEnable(GL_POLYGON_SMOOTH );
glEnable(GL_LINE_SMOOTH );
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glDepthMask(GL_FALSE);
  glPushMatrix();
    glTranslatef(0.0,0.0,-12.0);
    glRotatef(-3.6877,0.0,0.0,1.0);
    arriere->display();
  glPopMatrix();
  //enib
  glPushMatrix();
    glTranslatef(0.0,-0.664,0.0);
    glRotatef(-3.6877,0.0,0.0,1.0);
    glTranslatef(0.0,10.0,0.0);
    enib->display();
  glPopMatrix();
  //sol
  glPushMatrix();
    glTranslatef(-0.322,0.0,5.351);
    glRotatef(-3.6877,0.0,1.0,0.0);
    glTranslatef(0.0,0.0,-10.0);
    glRotatef(-90,1,0,0);
    sol->display();
  glPopMatrix();
  glDepthMask(GL_TRUE);
  glDisable(GL_BLEND);
}
*/

Background::Background()
{
  arriere = new Plan(40,40,"tex_arriere2.png");
 (arriere->getTexture())->setModePlaquage(GL_REPLACE);
  setPosition(0.0,0.0,-12.0);
}

Background::~Background()
{
  delete arriere;
}
void Background::display()
{
  glPushMatrix();
  _draw();
  glPopMatrix();
}
void Background::_draw()
{
    glTranslatef(0.0,0.0,-12.0);
    glRotatef(-3.6877,0.0,0.0,1.0);
    arriere->display();
}

Batiment::Batiment()
{
  enib = new Plan(20,20, "tex_enib.png");
 (enib->getTexture())->setModePlaquage(GL_REPLACE);
  setPosition(0.0,0.0,0.0);
}

Batiment::~Batiment()
{
 delete enib;
}

void Batiment::display()
{
  glPushMatrix();
  _draw();
  glPopMatrix();
}

void Batiment::_draw()
{
  glTranslatef(0.0,-0.664,0.0);
  glRotatef(-3.6877,0.0,0.0,1.0);
  glTranslatef(0.0,10.0,0.0);
  enib->display();
}

Sol::Sol()
{
  sol = new Plan(20,20,"tex_sol.png");
  (sol->getTexture())->setModePlaquage(GL_REPLACE);
  setPosition(0.0,0.0,-11.0);
}

Sol::~Sol()
{

}

void Sol::display()
{
  glPushMatrix();
  _draw();
  glPopMatrix();
}

void Sol::_draw()
{
    glTranslatef(-0.322,0.0,5.351);
    glRotatef(-3.6877,0.0,1.0,0.0);
    glTranslatef(0.0,0.0,-10.0);
    glRotatef(-90,1,0,0);
    sol->display();
}
